
***************************************************************************************************************
/*
THIS DO-FILE (CALLED FROM "GET_DATA_FOR_STRUCTURAL_ESTIMATION.DO"):

 1. Merges kid (potential) helper information to HRS sample, create a bunch of variables
 2. Create Appendix Tables 1,2,3,4 and Figure 1
 
*/
***************************************************************************************************************

clear all
set more off
set maxvar 20000

use "HRS_sample.dta", clear

merge m:1 h4hhid using near4, nogen keep(master match)
merge m:1 h5hhid using near5, nogen keep(master match)
merge 1:1 hhidpn using near6, nogen keep(master match)
merge 1:1 hhidpn using near7, nogen keep(master match)
merge 1:1 hhidpn using near8, nogen keep(master match)
merge 1:1 hhidpn using near9, nogen keep(master match)
merge 1:1 hhidpn using near10, nogen keep(master match)
merge 1:1 hhidpn using near11, nogen keep(master match)
merge 1:1 hhidpn using near12, nogen keep(master match)
	 
merge 1:1 hhidpn using helpavail4, nogen keep(master match)
merge 1:1 hhidpn using helpavail5, nogen keep(master match)
merge 1:1 hhidpn using helpavail6, nogen keep(master match)
merge 1:1 hhidpn using helpavail7, nogen keep(master match)
merge 1:1 hhidpn using helpavail8, nogen keep(master match)
merge 1:1 hhidpn using helpavail9, nogen keep(master match)
merge 1:1 hhidpn using helpavail10, nogen keep(master match)	
merge 1:1 hhidpn using helpavail11, nogen keep(master match)	
merge 1:1 hhidpn using helpavail12, nogen keep(master match)	

merge 1:1 hhidpn using "kidinfo.dta", nogen keep(master match) 

keep hhidpn ltci* lifei* nh* anyadl* ///
	 assets* income* age* single* haskid* numkids* ///
	 hasdaughter* kidinres* dauginres* kid10m* daug10m* kidhlpfut* daughlpfut* ///
	 nosib* nearrelatives* nearfriends* helpavail* housingassets* ///
	 nevermarried* cenreg* shlt* ragender raracem rahisp raeduc rarelig
	 
reshape long ltci lifei nh anyadl assets income age single haskid numkids hasdaughter kidinres dauginres ///
			 kid10m daug10m kidhlpfut daughlpfut nosib nearrelatives nearfriends helpavail housingassets ///
			 nevermarried cenreg shlt ///
		     , i(hhidpn) j(wave)
keep if wave>=4
drop if age==.

foreach var in hasdaughter kidinres dauginres kid10m daug10m kidhlpfut daughlpfut {
	replace `var'=0 if haskid==0
}

xtile wq=assets if age>=60 & age<70 & single==1, nq(5)
xtile iq=income if age>=60 & age<70 & single==1, nq(5)

gen nokid=(haskid==0) if haskid!=.
gen nokidnosib=(haskid==0 & nosib==1) if haskid!=. & nosib!=.
gen nokidnohelp=(haskid==0 & helpavail==5) if haskid!=. & helpavail!=.

forval w=1/5 {
	foreach var in haskid nokid nokidnosib nokidnohelp {
		gen `var'wq`w'=`var' if wq==`w'
		replace `var'wq`w'=0 if wq!=`w' & wq!=. & `var'!=.
	}
}	

gen ltci_kid=ltci if haskid==1
gen ltci_nokid=ltci if haskid==0
gen ltci_nokidnosib=ltci if haskid==0 & nosib==1
gen ltci_nokidnohelp=ltci if haskid==0 & helpavail==5
gen lifei_kid=lifei if haskid==1
gen lifei_nokid=lifei if haskid==0

gen 	numkidscapped=numkids
replace numkidscapped=8 if numkids>=8 & !mi(numkids)

gen ownhouse=(housingassets>0) if !mi(housingassets)

***************************************************************************************************************
*APPENDIX TABLES 1,2,3,4
local controls "i.wq i.iq c.age##c.age i.ragender i.raracem i.rahisp i.raeduc i.cenreg i.shlt i.rarelig i.wave i.ownhouse"

eststo clear
eststo: reg ltci `controls' haskid if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum haskid if e(sample)
estadd scalar xmean1=r(mean)
eststo: reg ltci `controls' haskid hasdaughter if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum haskid if e(sample)
estadd scalar xmean1=r(mean)
sum hasdaughter if e(sample)
estadd scalar xmean2=r(mean)
eststo: reg ltci `controls' haskid hasdaughter kid10m kidhlpfut if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum haskid if e(sample)
estadd scalar xmean1=r(mean)
sum hasdaughter if e(sample)
estadd scalar xmean2=r(mean)
sum kidinres if e(sample)
estadd scalar xmean3=r(mean)
sum kidhlpfut if e(sample)
estadd scalar xmean4=r(mean)
eststo: reg ltci `controls' haskidwq* if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum haskid if e(sample)
estadd scalar xmean1=r(mean)
esttab using LTCI_controls.tex, replace booktabs nonotes b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) keep(haskid haskidwq* hasdaughter kid10m kidhlpfut) ///
	   stats(ymean xmean1 xmean2 xmean3 xmean4 N, labels("Means \\ \quad LTC insurance rate" "\quad Has child" "\quad Has daughter" ///
	         "\quad Has child within 10 miles" "\quad Child helpful in future") fmt(3 a3 a3 a3 a3 a3)) ///
	   		mgroups("LTC insurance coverage (binary)", pattern(1 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule{@span})) nomtitles ///
	   varlabels(haskid "Has child" haskidwq1 "Has child, wealth Q1 (poorest)" haskidwq2 "Has child, wealth Q2" haskidwq3 "Has child, wealth Q3" ///
				 haskidwq4 "Has child, wealth Q4" haskidwq5 "Has child, wealth Q5 (wealthiest)" hasdaughter "Has daughter" ///
				 kid10m "Has child within 10 miles" kidhlpfut "Child helpful in future") 

eststo clear
eststo: reg ltci `controls' haskid if age>=60 & age<70 & single==1, cluster(hhidpn)
eststo: reg ltci `controls' i.numkidscapped if age>=60 & age<70 & single==1, cluster(hhidpn)
esttab using LTCI_controls_numkids.tex, replace booktabs nonotes b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) keep(haskid *numkidscapped) drop(0.numkidscapped) ///
	   stats(N, labels("Observations") fmt(a3)) ///
	   		mgroups("LTC insurance coverage (binary)", pattern(1 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule{@span})) nomtitles ///
	   varlabels(haskid "Has child" 1.numkidscapped "Has one child" 2.numkidscapped "Has two children" 3.numkidscapped "Has three children" ///
				 4.numkidscapped "Has four children" 5.numkidscapped "Has five children" 6.numkidscapped "Has six children" 7.numkidscapped "Has seven children" ///
				 8.numkidscapped "Has eight or more children") 
				 
eststo clear
local controls "i.wq i.iq c.age##c.age i.ragender i.raracem i.rahisp i.raeduc i.cenreg i.shlt i.rarelig i.wave i.ownhouse"
eststo: reg ltci `controls' nokidwq* if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum nokid if e(sample)
estadd scalar xmean1=r(mean)
eststo: reg ltci `controls' nokidnosibwq* if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum nokidnosib if e(sample)
estadd scalar xmean2=r(mean)
eststo: reg ltci `controls' nokidnohelpwq* if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
sum nokidnohelp if e(sample)
estadd scalar xmean3=r(mean)
esttab using LTCI_more_controls.tex, replace booktabs nonotes b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) keep(nokidwq* nokidnosibwq* nokidnohelpwq*) ///
	   stats(ymean xmean1 xmean2 xmean3 N, labels("Means \\ \quad LTC insurance rate" "\quad No children" "\quad No children, no siblings" ///
	         "\quad No children, no future help") fmt(3 a3 a3 a3 a3)) ///
	   		mgroups("LTC insurance coverage (binary)", pattern(1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule{@span})) nomtitles ///
	   varlabels(nokidwq1 "No children, wealth Q1 (poorest)" nokidwq2 "No children, wealth Q2" nokidwq3 "No children, wealth Q3" ///
				 nokidwq4 "No children, wealth Q4" nokidwq5 "No children, wealth Q5 (wealthiest)" ///
				 nokidnosibwq1 "No children, no siblings, wealth Q1 (poorest)" nokidnosibwq2 "No children, no siblings, wealth Q2" nokidnosibwq3 "No children, no siblings, wealth Q3" ///
				 nokidnosibwq4 "No children, no siblings, wealth Q4" nokidnosibwq5 "No children, no siblings, wealth Q5 (wealthiest)" ///
				 nokidnohelpwq1 "No children, no future help, wealth Q1 (poorest)" nokidnohelpwq2 "No children, no future help, wealth Q2" nokidnohelpwq3 "No children, no future help, wealth Q3" ///
				 nokidnohelpwq4 "No children, no future help, wealth Q4" nokidnohelpwq5 "No children, no future help, wealth Q5 (wealthiest)" ///
				 ) 	   				 
				 
*other outcomes: life insurance, nursing home care, anyadls
gen poorhealth=(shlt==5) if inlist(shlt,1,2,3,4,5)

xtile wq80=assets if age>=80 & single==1, nq(5)
xtile iq80=income if age>=80 & single==1, nq(5)

eststo clear
local controls "i.wq i.iq c.age##c.age i.ragender i.raracem i.rahisp i.raeduc i.cenreg i.shlt i.rarelig i.wave i.ownhouse"
eststo: reg lifei haskid `controls' if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
local controls "i.wq80 i.iq80 c.age##c.age i.ragender i.raracem i.rahisp i.raeduc i.cenreg i.shlt i.rarelig i.wave i.ownhouse"
eststo: reg nh haskid `controls' if age>=80 & single==1, cluster(hhidpn)
estadd ysumm
local controlsnohlth "i.wq80 i.iq80 c.age##c.age i.ragender i.raracem i.rahisp i.raeduc i.cenreg i.rarelig i.wave i.ownhouse"
eststo: reg anyadl haskid `controlsnohlth' if age>=80 //or fair/poor health: no movement here (so health exog)
estadd ysumm
local controls "i.wq i.iq c.age##c.age i.ragender i.raracem i.rahisp i.raeduc i.cenreg i.shlt i.rarelig i.wave"
eststo: reg ownhouse haskid `controls' if age>=60 & age<70 & single==1, cluster(hhidpn)
estadd ysumm
esttab using otheroutcomes.tex, replace booktabs nonotes b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) keep(haskid) ///
	   stats(ymean N, labels("Dependent variable mean") fmt(a3)) ///
	   mtitles("Life insurance" "Nursing home (80+)" "Any ADL (80+)" "Own home") ///
	   varlabels(haskid "Has child") ///
	   
***************************************************************************************************************
   
***************************************************************************************************************
*FIGURE 1

collapse ltci_kid ltci_nokid ltci_nokidnosib ltci_nokidnohelp lifei_kid lifei_nokid if age>=60 & age<70 & single==1, by(wq)

*LTCI: kids vs no kids (main graph)
twoway connected ltci_kid wq, color(red) lwidth(thick) || ///
	   connected ltci_nokid wq, lwidth(thick) color(blue) ///
	   legend(order(1 2) label(1 "Has Children") label(2 "No Children")) ylabel(0(.1).3) yscale(range(0(.1).3)) ///
	   ytitle(LTC insurance coverage) xtitle(Parent Wealth Quintile) xlabel(1 2 3 4 5, valuelabel) ///
	   graphregion(color(white))
cap erase LTCIrates_nocontrols.pdf
graph export LTCIrates_nocontrols.pdf, as(pdf)

***************************************************************************************************************

/*
forval x=4/12 {
	erase helpavail`x'.dta
	erase near`x'.dta
}
*/
